import { IPSAppCounterRef } from '../../app/control/ipsapp-counter-ref';
import { IPSAppViewUIAction } from '../../app/view/ipsapp-view-uiaction';
import { IPSSysPanelButton } from './ipssys-panel-button';
import { PSSysPanelItemImpl } from './pssys-panel-item-impl';
import { IPSUIAction } from '../../view/ipsuiaction';

export class PSSysPanelButtonImpl extends PSSysPanelItemImpl implements IPSSysPanelButton {
  get actionType():
    | 'NONE'
    | 'UIACTION'
    | 'UILOGIC'
    | 'OPENVIEW'
    | 'OPENDEVIEW'
    | 'OPENSYSPDTVIEW'
    | 'OPENHTMLPAGE'
    | 'DATA_CREATEOBJECT'
    | 'DATA_SAVECHANGES'
    | 'DATA_CANCELCHANGES'
    | 'DATA_REMOVEOBJECT'
    | 'DATA_SYNCHRONIZE'
    | 'VIEW_OKACTION'
    | 'VIEW_CANCELACTION'
    | 'VIEW_YESACTION'
    | 'VIEW_NOACTION'
    | 'UTIL_ADDSELECTION'
    | 'UTIL_REMOVESELECTION'
    | 'UTIL_ADDALL'
    | 'UTIL_REMOVEALL'
    | 'UTIL_PREVSTEP'
    | 'UTIL_NEXTSTEP'
    | 'UTIL_FINISH'
    | 'UTIL_SEARCH'
    | 'UTIL_RESET'
    | 'APP_LOGIN'
    | 'APP_LOGOUT'
    | 'CUSTOM' {
    return this.M.actionType;
  }

  get borderStyle(): string {
    return this.M.borderStyle;
  }

  get buttonCssStyle(): string {
    return this.M.buttonCssStyle;
  }

  get buttonHeight(): number {
    return this.M.buttonHeight != null ? this.M.buttonHeight : 0.0;
  }

  get buttonStyle(): string {
    return this.M.buttonStyle;
  }

  get buttonType(): string {
    return this.M.buttonType || 'PANELBUTTON';
  }

  get buttonWidth(): number {
    return this.M.buttonWidth != null ? this.M.buttonWidth : 0.0;
  }

  get captionItemName(): string {
    return this.M.captionItemName;
  }

  get cssStyle(): string {
    return this.M.cssStyle;
  }

  get iconAlign(): 'LEFT' | 'TOP' | 'RIGHT' | 'BOTTOM' {
    return this.M.iconAlign;
  }

  protected psappcounterref: IPSAppCounterRef | null = null;

  getPSAppCounterRef(): IPSAppCounterRef | null {
    if (this.psappcounterref != null) return this.psappcounterref;
    const value = this.M.getPSAppCounterRef;
    if (value == null) {
      return null;
    }
    this.psappcounterref = this.getPSModel4('app.control.IPSAppCounterRef', value, 'getPSAppCounterRef') as IPSAppCounterRef;
    return this.psappcounterref;
  }

  get psAppCounterRef(): IPSAppCounterRef | null {
    return this.getPSAppCounterRef();
  }

  getPSAppCounterRefMust(): IPSAppCounterRef {
    const value = this.getPSAppCounterRef();
    if (value == null) {
      throw new Error('未指定应用计数器引用');
    }
    return value;
  }

  protected psappviewuiaction: IPSAppViewUIAction | null = null;

  getPSAppViewUIAction(): IPSAppViewUIAction | null {
    if (this.psappviewuiaction != null) return this.psappviewuiaction;
    const value = this.M.getPSAppViewUIAction;
    if (value == null) {
      return null;
    }
    this.psappviewuiaction = this.getPSModel4('app.view.IPSAppViewUIAction', value, 'getPSAppViewUIAction') as IPSAppViewUIAction;
    return this.psappviewuiaction;
  }

  get psAppViewUIAction(): IPSAppViewUIAction | null {
    return this.getPSAppViewUIAction();
  }

  getPSAppViewUIActionMust(): IPSAppViewUIAction {
    const value = this.getPSAppViewUIAction();
    if (value == null) {
      throw new Error('未指定应用视图界面行为');
    }
    return value;
  }

  protected psuiaction: IPSUIAction | null = null;

  getPSUIAction(): IPSUIAction | null {
    if (this.psuiaction != null) return this.psuiaction;
    const value = this.M.getPSUIAction;
    if (value == null) {
      return null;
    }
    this.psuiaction = this.getPSModel4('view.IPSUIAction', value, 'getPSUIAction') as IPSUIAction;
    return this.psuiaction;
  }

  get psUIAction(): IPSUIAction | null {
    return this.getPSUIAction();
  }

  getPSUIActionMust(): IPSUIAction {
    const value = this.getPSUIAction();
    if (value == null) {
      throw new Error('未指定调用界面行为');
    }
    return value;
  }

  get renderMode(): 'BUTTON' | 'LINK' {
    return this.M.renderMode || 'BUTTON';
  }

  get tooltip(): string {
    return this.M.tooltip;
  }

  get uIActionParamJO(): IModel {
    return this.M.uIActionParamJO;
  }

  get uIActionTarget(): 'SINGLEDATA' | 'SINGLEKEY' | 'MULTIDATA' | 'MULTIKEY' | 'NONE' {
    return this.M.uIActionTarget;
  }

  get xDataControlName(): string {
    return this.M.xDataControlName;
  }

  get saveTargetFirst(): boolean {
    return this.M.saveTargetFirst != null ? this.M.saveTargetFirst : false;
  }

  get cls(): string {
    return 'PSSysPanelButtonImpl';
  }

  instanceof(cls: string): boolean {
    if (
      cls == 'app.view.IPSAppViewUIAction' ||
      cls == 'app.view.IPSUIActionItem' ||
      cls == 'control.IPSButtonBase' ||
      cls == 'control.panel.IPSPanelButton' ||
      cls == 'control.panel.IPSSysPanelButton'
    )
      return true;
    return super.instanceof(cls);
  }
}
